home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / dos / seek.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  102 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: seek.c,v 1.3 1996/08/13 13:52:51 digulla Exp $
  4.     $Log: seek.c,v $
  5.     Revision 1.3  1996/08/13 13:52:51  digulla
  6.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  7.     Replaced __AROS_LA by __AROS_LHA
  8.  
  9.     Revision 1.2  1996/08/01 17:40:57  digulla
  10.     Added standard header for all files
  11.  
  12.     Desc:
  13.     Lang: english
  14. */
  15. #include <clib/exec_protos.h>
  16. #include <dos/filesystem.h>
  17. #include "dos_intern.h"
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <clib/dos_protos.h>
  23.  
  24.     __AROS_LH3(LONG, Seek,
  25.  
  26. /*  SYNOPSIS */
  27.     __AROS_LHA(BPTR, file,     D1),
  28.     __AROS_LHA(LONG, position, D2),
  29.     __AROS_LHA(LONG, mode,     D3),
  30.  
  31. /*  LOCATION */
  32.     struct DosLibrary *, DOSBase, 11, Dos)
  33.  
  34. /*  FUNCTION
  35.     Changes the actual read/write position in a file and/or
  36.     reads the actual position, e.g to get the actual position
  37.     do a Seek(file,0,OFFSET_CURRENT).
  38.  
  39.     This function may fail (obviously) on certain devices such
  40.     as pipes or console handlers.
  41.  
  42.     INPUTS
  43.     file     - filehandle
  44.     position - relative offset in bytes (positive, negative or 0).
  45.     mode     - Where to count from. Either OFFSET_BEGINNING,
  46.            OFFSET_CURRENT or OFFSET_END.
  47.  
  48.     RESULT
  49.     Absolute position in bytes before the Seek(), -1 if an error
  50.     happened. IoErr() will give additional information in that case.
  51.  
  52.     NOTES
  53.  
  54.     EXAMPLE
  55.  
  56.     BUGS
  57.  
  58.     SEE ALSO
  59.  
  60.     INTERNALS
  61.  
  62.     HISTORY
  63.     29-10-95    digulla automatically created from
  64.                 dos_lib.fd and clib/dos_protos.h
  65.  
  66. *****************************************************************************/
  67. {
  68.     __AROS_FUNC_INIT
  69.     __AROS_BASE_EXT_DECL(struct DosLibrary *,DOSBase)
  70.  
  71.     /* Get pointer to filehandle */
  72.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  73.  
  74.     /* Get pointer to process structure */
  75.     struct Process *me=(struct Process *)FindTask(NULL);
  76.  
  77.     /* Get pointer to I/O request. Use stackspace for now. */
  78.     struct IOFileSys io,*iofs=&io;
  79.  
  80.     /* Prepare I/O request. */
  81.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  82.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  83.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  84.     iofs->IOFS.io_Device =fh->fh_Device;
  85.     iofs->IOFS.io_Unit     =fh->fh_Unit;
  86.     iofs->IOFS.io_Command=FSA_SEEK;
  87.     iofs->IOFS.io_Flags  =0;
  88.     iofs->io_Args[0]=position<0?-1:0;
  89.     iofs->io_Args[1]=position;
  90.     iofs->io_Args[2]=mode;
  91.  
  92.     /* Send the request. */
  93.     DoIO(&iofs->IOFS);
  94.  
  95.     /* return */
  96.     if((me->pr_Result2=iofs->io_DosError))
  97.     return -1;
  98.     else
  99.     return iofs->io_Args[1];
  100.     __AROS_FUNC_EXIT
  101. } /* Seek */
  102.